package com.wjc.train.business.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjc.train.business.req.DailyTrainQueryReq;
import com.wjc.train.business.req.DailyTrainSaveReq;
import com.wjc.train.business.resp.DailyTrainQueryResp;
import com.wjc.train.business.service.IDailyTrainService;
import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.common.untils.PageUtil;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 每日车次表 前端控制器
 * </p>
 *
 * @author Guessed
 * @since 2023-08-07
 */
@RestController
@Validated
@RequestMapping("/admin/daily-train")
public class DailyTrainController {

    @Resource
    private IDailyTrainService dailytrainService;

    @PostMapping("/save")
    public CommonResp save(@RequestBody @Valid DailyTrainSaveReq dailytrainSaveReq){
        dailytrainService.save(dailytrainSaveReq);
        return CommonResp.success();
    }

    @PostMapping("/query-list")
    public CommonResp save(@RequestBody DailyTrainQueryReq dailytrainQueryReq){
        IPage<DailyTrainQueryResp> iPage =
        dailytrainService.queryList(PageUtil.getPage(dailytrainQueryReq.getQueryPage()), dailytrainQueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        dailytrainService.delete(id);
        return CommonResp.success();
    }

    @GetMapping("/gen-daily/{date}")
    public CommonResp genDaily(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        dailytrainService.genDaily(date);
        return CommonResp.success();
    }
}


